package br.com.atid.view.util
{
    import com.esri.ags.Map;
    import com.esri.ags.geometry.Geometry;
    import com.esri.ags.geometry.MapPoint;
    import com.esri.ags.geometry.Polyline;
    import com.esri.ags.symbol.Symbol;
    
    import flash.display.Graphics;
    import flash.display.Sprite;

    public class DashedLineSymbol extends Symbol
    {
        private var m_decorator : DashedLineDecorator = new DashedLineDecorator();
        private var m_decoratorFunc : Function;
        
        public function DashedLineSymbol()
        {
            super();
        }
        
        override public function clear(sprite:Sprite):void
        {
            sprite.graphics.clear();                   
        }        
        
        override public function draw(sprite:Sprite, geometry:Geometry, attributes:Object, map:Map):void
        {
            if( geometry is Polyline )
            {
                sprite.graphics.lineStyle( 2, 0xFF0000);
                const polyline : Polyline = Polyline(geometry);
                for each ( var path : Array in polyline.paths )
                {
                    m_decoratorFunc = moveTo;
                    for each ( var mapPoint : MapPoint in path)
                    {
                        m_decoratorFunc( sprite.graphics, mapPoint, map);
                    }
                }
            }
        }
        
        private function moveTo( graphics : Graphics, mapPoint : MapPoint, map : Map ) : void
        {
            m_decorator.moveTo(toScreenX(map,mapPoint.x), toScreenY(map,mapPoint.y), graphics);
            m_decoratorFunc = lineTo;
        }
        
        private function lineTo( graphics : Graphics, mapPoint : MapPoint, map : Map ) : void
        {
            m_decorator.lineTo(toScreenX(map,mapPoint.x), toScreenY(map,mapPoint.y), graphics);
        }
        
        
    }
}